<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/6/15
  Time: 20:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>留言</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body style="background-color:#7fecba">
<br>
<br>
<br>
<form class="layui-form layui-row layui-col-space16">
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-username"></i>
            </div>
            <input type="text" name="username" value="" placeholder="留言人" class="layui-input" lay-affix="clear">
        </div>
    </div>
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <input type="text" name="content" placeholder="留言内容" lay-affix="clear" class="layui-input">
        </div>
    </div>
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-form-item layui-inline">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-date"></i>
                </div>
                <input type="text" id="date1" class="layui-input" name="post_date" autocomplete="off"
                       placeholder="留言日期">
            </div>
        </div>

    </div>
    <div class="layui-btn-container layui-col-xs12">
        <button style="margin-left: 10px" class="layui-btn" lay-submit lay-filter="demo-table-search">搜索</button>
        <button type="reset" class="layui-btn layui-btn-primary">清空</button>
        <button type="button" class="layui-btn " lay-on="test-iframe-handle">
            发布留言
            <span id="ID-test-iframe-mark"></span>
        </button>
    </div>
</form>
<table class="layui-hide" id="ID-table-demo-search" lay-filter="test"></table>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script src="/layui/layui.js"></script>
<script>
    layui.use(function () {
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        laydate.render({elem: "#date1", range: "~", trigger: 'click'});
        // 创建表格实例
        table.render({
            elem: '#ID-table-demo-search',
            url: '/messagefindall', // 此处为静态模拟数据，实际使用时需换成真实接口
            cols: [[
                {field: 'username', title: '留言人', width: 100},
                {field: 'content', title: '留言内容'},
                {
                    field: 'post_date', title: '留言日期', sort: true, width: 200, templet: function (d) {
                        return util.toDateString(d.post_date * 1000, "yyyy-MM-dd HH:mm:ss")
                    }
                },
            ]],
            page: true,
        });
        // 日期
        laydate.render({
            elem: '.demo-table-search-date'
        });
        // 搜索提交
        form.on('submit(demo-table-search)', function (data) {
            var field = data.field; // 获得表单字段
            // 执行搜索重载

            table.reload('ID-table-demo-search', {
                url: 'findcontent',
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            return false; // 阻止默认 form 跳转
        });
        util.on('lay-on', {
            'test-iframe-handle': function () {
                layer.open({
                    type: 2,
                    area: ['680px', '520px'],
                    content: '/addMessage.jsp',
                    fixed: false, // 不固定
                    maxmin: true,
                    shadeClose: true,
                });
            }
        });
    });
</script>

</body>
</html>